package com.digitalchina.lxnsy.viewholder;

import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.DataMallVO;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.Utils;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：白彦东
 * 创建时间：2016/12/28 18:10
 * 修改备注：
 * ================================================
 */

public class DataMallHolder extends BaseViewHolder<DataMallVO> {

//    private View contentView;
    private SimpleDraweeView ivImage;
    private TextView tvTitle;
    private TextView tvSummary;
    private TextView tvPrice;
    private TextView tvType;

//    private Button btnAddCart;

    public DataMallHolder(ViewGroup parent) {
        super(parent, R.layout.item_data_mall_list);
//        contentView = $(R.id.swipe_content);
        ivImage = $(R.id.item_iv_images);
        tvTitle = $(R.id.item_tv_title);
        tvSummary = $(R.id.item_tv_summary);
        tvPrice = $(R.id.item_tv_price);
        tvType = $(R.id.item_tv_type);
//        btnAddCart = $(R.id.item_btn_add_cart);
    }

    @Override
    public void setData(DataMallVO data) {
        super.setData(data);

//        Utils.displayImage(getContext(), data.getImages() != null ? data.getImages() : "", ivImage);
        FrescoUtil.showImageSmall(data.getImages() != null ? data.getImages() : "", ivImage);
        tvTitle.setText(data.getTitle() != null ? data.getTitle() : "");
        tvSummary.setText(data.getSummary() != null ? data.getIntroduce() : "");
        tvPrice.setText(String.format("￥ %s", data.getAmount_num() != null ? Utils.formatPrice(data.getAmount_num()) : ""));
        tvType.setText(data.getResourceType() != null ? data.getResourceType() : "");

//        btnAddCart.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (null != mOnSwipeListener) {
//                    mOnSwipeListener.onAddCart(getAdapterPosition());
//                }
//            }
//        });
//
//        contentView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (null != mOnSwipeListener) {
//                    mOnSwipeListener.onItemClick(getAdapterPosition());
//                }
//            }
//        });

    }

    /**
     * 和Activity通信的接口
     */
    public interface onSwipeListener {
        void onAddCart(int pos);

        void onItemClick(int pos);
    }

    private onSwipeListener mOnSwipeListener;

    public void setOnDelListener(onSwipeListener mOnDelListener) {
        this.mOnSwipeListener = mOnDelListener;
    }
}
